﻿namespace eProject.ViewModel.Commands
{
    public class SwitchItemsCommand<T> : ICommand
    {
        

        private bool _isCanceled;
        private bool _isExecuted;
        private readonly SwitchItemsDelegate _switchItemsDelegate;
        private readonly T _item1;
        private readonly T _item2;

        public delegate void SwitchItemsDelegate(T item1, T item2);

        public SwitchItemsCommand(SwitchItemsDelegate switchItemsDelegate, T firstItem, T secondItem)
        {
            _switchItemsDelegate = switchItemsDelegate;
            _item1 = firstItem;
            _item2 = secondItem;
        }

        public void Execute()
        {
            if (_isExecuted) return;

            _switchItemsDelegate(_item1, _item2);
                
            _isExecuted = true;
            _isCanceled = false;
        }

        public void Unexecute()
        {
            if (_isCanceled) return;

            _switchItemsDelegate(_item1, _item2);

            _isCanceled = true;
            _isExecuted = false;
        }
    }
}
